using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sfcms.api;

public partial class sfcms_sfcms_file : webpagebase
{
    protected override void Page_Load()
    {
        SetPageTitle("File Properties");

        object[] folderAndItem = GetFolderAndItemFromQueryString(2);

        folder f = folderAndItem[0] as folder;
        file theFile = folderAndItem[1] as file;

        if (IsPostBack)
        {
            if (filedata.PostedFile == null || filedata.PostedFile.ContentLength == 0)
            {
                SetWarningMessage("Please select a file");
                return;
            }

            if (theFile != null)
            {
                theFile.update(filedata.PostedFile);
            }
            else
            {
                file newFile = file.fromupload(filedata.PostedFile);
                newFile.setparent(f.id);
                Response.Redirect("/web/sfcms/sfcms_file.aspx?key=" + f.id + "/" + newFile.id);
            }
        }

        if (theFile != null)
        {
            if (theFile.isimage)
            {
                filedisplayordownload.Text = "<img src=\"/web/sfcms/sfcms_download.aspx?id=" + theFile.id + "\" />";
            }
            else
            {
                filedisplayordownload.Text = "<a href=\"/web/sfcms/sfcms_download.aspx?id=" + theFile.id + "\">Download the File</a>";
            }
            filename.Text = theFile.filename + "." + theFile.fileextension;
            filecontenttype.Text = theFile.contenttype;
            filesize.Text = theFile.size + " bytes";
        }





    }
}
